package demo;

import java.util.Set;
import java.util.TreeSet;

public class Solution {
    public int numJewelsInStones(String jewels, String stones) {
        //字符串转换成数组
        char[]j=jewels.toCharArray();
        char[]s=stones.toCharArray();
        //创建集合
        Set<Character> jewelsSet = new TreeSet<>();
        //遍历每个字符
        for(char e:j){
            //放入集合
            jewelsSet.add(e);
        }
        //记录个数
        int count=0;
        for(char c:s){
            //遍历字符
            if(jewelsSet.contains(c)){
                //是否包含字符
                count++;
            }
        }
        return count;


    }
}
